﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using TomanuExtensions;
using TomanuExtensions.Utils;

namespace AmiEmuLib.AmigaConfiguration.FloppiesConfig
{
    /// <summary>
    /// Floppy configuration.
    /// </summary>
    public class Floppy : XmlBase
    {
        /// <summary>
        /// Floppy speed.
        /// </summary>
        public FloppySpeed Speed;

        /// <summary>
        /// Should be between 0..100. Floppy sound volume.
        /// </summary>
        public int Volume;

        /// <summary>
        /// Look at AmiEmuLib.Configuration.FloppySound.FloppySoundsList. Each floppy can have its 
        /// own sounds.
        /// </summary>
        public string Sounds = "";

        /// <summary>
        /// Path to floppy image file.
        /// </summary>
        public string ImagePath = "";

        /// <summary>
        /// Floppy type.
        /// </summary>
        public FloppyType Type = FloppyType.Disable;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_reader"></param>
        public Floppy(XmlReader a_reader)
            : base(a_reader)
        {
        }

        protected override void ReadXml(XmlReader a_reader)
        {
            Type = a_reader.GetAttributeEnum<FloppyType>("Type");

            a_reader.ReadStartElement(GetType().Name);

            Speed = a_reader.ReadElementContentAsEnum<FloppySpeed>("Speed");
            Volume = a_reader.ReadElementContentAsInt("Volume");
            Sounds = a_reader.ReadElementContentAsString("Sounds");
            ImagePath = a_reader.ReadElementContentAsString("ImagePath");

            a_reader.ReadEndElement();
        }

        public override void WriteXml(XmlWriter a_writer)
        {
            a_writer.WriteStartElement(GetType().Name);

            a_writer.WriteAttribute("Type", Type);
            a_writer.WriteElement("Speed", Speed);
            a_writer.WriteElement("Volume", Volume);
            a_writer.WriteElement("Sounds", Sounds);
            a_writer.WriteElement("ImagePath", ImagePath);
            
            a_writer.WriteEndElement();
        }
    }
}
